<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>鑫乐居——注册</title>
	<link href="css/bootstrap.min.css" rel="stylesheet">
	<script src="js/jquery.js"></script>
  <script src="js/bootstrap.min.js"></script>
  <meta name="viewport" content="width=device-width,initial-scale=1.0">
  <link rel="stylesheet" href="css/zhuce.css">
 <!-- <script type="text/javascript" src="js/indexform.js"></script>
	<!--[if it IE 9]>
	<scritp src="html5shiv.js"></script>
	<script src="respond.min.js"></script>
	<![end if]-->
	<script type="text/javascript">
		window.onload = function () {
			var email = document.getElementById('email');
			var pass1 = document.getElementById('password1');
			var pass2 = document.getElementById('password2');
			var yzm = document.getElementById('yanzheng');
			var che = document.getElementById('tongyi');
			var tijiao = document.getElementById('tijiao'); 
			var	bd = document.getElementById('bd');
			email.onblur = function () {
				if (email.value != (/^[0-9A-Za-z_@]$/) ) {
					alert("格式不正确！");
				}
			}
			pass2.onblur = function () {
				if (pass2.value != pass1.value) {
					alert("两次密码输入不一致！");
				}
			}
			 code = "";   
     		var codeLength = 4;//验证码的长度  
		     var checkCode = document.getElementById("code");   
		     var random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',  
		     'S','T','U','V','W','X','Y','Z');//随机数  
		     for(var i = 0; i < codeLength; i++) {//循环操作  
		        var index = Math.floor(Math.random()*36);//取得随机数的索引（0~35）  
		        code += random[index];//根据索引取得随机数加到code上  
		    }  
		    checkCode.value = code;
		    yzm.onblur = function () {
		    	if (yzm.value != checkCode.value) {
		    		alert("验证码输入错误！")
		    	}
		    }
		    tijiao.onclick = function() {
		    	if (!che.checked) {
		    		alert("请选择 同意“服务条款”和“隐私权相关政策”");
		    		bd.action = "";
		    	}
		    }
		    
		    
		}
		
	</script>
</head>
<body>
	<form action="zhuce.php" method="post" id="bd">
		<div id="cont">
		<!-- 头部，包括logo，导航 -->
			<div id="head">
				<div class="logo"></div>
				<div class="tel">
					<div class="phone"></div>
					<span>400-160-140</span>
				</div>
			</div>
			<!-- 注册界面 -->
			<div id="zc">
				<div class="ts">
					<p>欢迎注册鑫乐居 我们会竭诚为您服务！欢迎下载鑫乐居APP</p>
				</div>
				<div class="cont">
					<div class="cont1">
						<span>用户名：</span>
						<input type="text" class="form-control" id="email" name="username">
						<p>6~18个字符，可以使用字母、数字、下划线，需以字母开头</p>
					</div>
					<div class="cont2">
						<span>密码：</span>
						<input type="password" class="form-control" id="password1" name='password'>
						<p>6~16个字符，区分大小写</p>
					</div>
					<div class="cont3">
						<span>确认密码：</span>
						<input type="password" class="form-control" id="password2">
						<p>请再次填写密码</p>
					</div>
					<div class="cont4">
						<span>验证码：</span>
						<input type="text" class="form-control" id="yanzheng">
						<p>请填写图片中的字符，区分大小写</p>
						<input type="text" readonly="ture" id="code">
					</div>
					<div class="tongyi">
						<input type="checkbox" id="tongyi">
						<span>同意“服务条款”和“隐私权相关政策”</span>
					</div>
					<input type="submit" class="btn btn-warning" value="立即注册" id="tijiao" name='submit'>
				</div>
				<div class="rig">
					<div class="down"></div>
				</div>
			</div>
			<div id="foot">
				<span>Copyright  2010-2015 All Rights Reserved. 京ICP备15041059号-1 京公网安备11010502027337 北京瑞卓喜创科技发展有限公司版权所有</span>
			</div>
		</div>
	</form>
	<?php 
			include "shuju.php";
			if(isset($_POST["submit"])){
			$username = $_POST["username"];
			$password = md5($_POST["password"]);
			$db = new DB();
			$sql = "select * from user where name = '$username'";
			if ($db->get($sql)) {
				echo "已经注册！";
			}else{
				$sql = "insert into user values(null,'$username','$password',null,null,0)";
			$db->insert($sql);
			echo "<script>alert('注册成功！');location.href='login.html';</script>";
			}
		}

		 ?>
</body>
</html>
